﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BL
{
    class EdgeDataSet
    {
        private DataSet m_ds;

        public EdgeDataSet(DataSet ds)
        {
            m_ds = ds;
        }

        public List<Edge> ToEdges()
        {
            List<Edge> edges = new List<Edge>();

            if (m_ds.Tables.Count > 0)
            {
                DataTable dt = m_ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    Edge edge = new Edge(Convert.ToInt32(dr["id"]),
                                              Convert.ToInt32(dr["in_vertex_id"]),
                                              Convert.ToDouble(dr["in_latitude"]),
                                              Convert.ToDouble(dr["in_longtitude"]),
                                              Convert.ToInt32(dr["out_vertex_id"]),
                                              Convert.ToDouble(dr["out_latitude"]),
                                              Convert.ToDouble(dr["out_longtitude"]),
                                              Convert.ToDouble(dr["weight"]));

                    edges.Add(edge);
                }
            }

            return edges;
        }
    }
}
